import axios from 'axios';
import { ethers } from 'ethers';

const BASE_URL = 'http://localhost:3000/api/v1';

async function debugI18n() {
    console.log('🔍 调试 i18n 翻译服务...\n');

    // 使用ethers进行离线签名
    const testPrivateKey = '9b225c646ba70c3e57756bdc8e30d6ac0fa5b614ed9baae00e92740713894eb2';
    const wallet = new ethers.Wallet(testPrivateKey);
    const message = 'Welcome to RWA Platform! Please sign this message to authenticate.';
    const signature = await wallet.signMessage(message);

    // 测试中文
    console.log('📝 测试中文 (zh):');
    try {
        const response = await axios.post(`${BASE_URL}/auth/wallet-login?lang=zh`, {
            walletAddress: wallet.address,
            message: message,
            signature: signature,
            chainId: 1,
            fullName: 'Test User'
        });

        console.log(`  状态码: ${response.status}`);
        console.log(`  响应语言: ${response.headers['content-language']}`);
        console.log(`  完整响应:`, JSON.stringify(response.data, null, 2));
    } catch (error: any) {
        console.log(`  错误状态码: ${error.response?.status}`);
        console.log(`  响应语言: ${error.response?.headers['content-language']}`);
        console.log(`  错误响应:`, JSON.stringify(error.response?.data, null, 2));
    }

    // 测试英文
    console.log('\n📝 测试英文 (en):');
    try {
        const response = await axios.post(`${BASE_URL}/auth/wallet-login?lang=en`, {
            walletAddress: wallet.address,
            message: message,
            signature: signature,
            chainId: 1,
            fullName: 'Test User'
        });

        console.log(`  状态码: ${response.status}`);
        console.log(`  响应语言: ${response.headers['content-language']}`);
        console.log(`  完整响应:`, JSON.stringify(response.data, null, 2));
    } catch (error: any) {
        console.log(`  错误状态码: ${error.response?.status}`);
        console.log(`  响应语言: ${error.response?.headers['content-language']}`);
        console.log(`  错误响应:`, JSON.stringify(error.response?.data, null, 2));
    }
}

debugI18n().catch(console.error);
